package com.xbongbong.workflow.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.AccessLinkEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 工作流类型
 * @author 魏荣杰
 * @date 2021/5/10 15:50
 * @since
 * @version
 */
@Getter
public enum WorkflowNodeTypeEnum {

    /**
     * 开始节点
     */
    START_NODE(1, "startNode", "开始节点", "", null),
    /**
     * 结束节点
     */
    END_NODE(2, "endNode", "结束节点", "", null),
    /**
     * 流程节点
     */
    APPROVE_NODE(3, "approveNode", "流程节点", "enum.workflowNodeType.memo.approve_node", AccessLinkEnum.APPROVE_NODE),
    /**
     * 抄送节点
     */
    CC_NODE(4, "ccNode", "抄送节点", "enum.workflowNodeType.memo.cc_node", AccessLinkEnum.CC_NODE),
    /**
     * 条件节点
     */
    CONDITION_NODE(5, "conditionNode", "条件节点", "enum.workflowNodeType.memo.condition_node", AccessLinkEnum.CONDITION_NODE),
    /**
     * 条件块节点
     */
    CONDITION_BLOCK_NODE(6, "conditionBlockNode", "条件块节点", "", null),
    /**
     * 新建记录节点
     */
    CREATE_NODE(11, "createNode", "新建记录节点", "enum.workflowNodeType.memo.create_node", AccessLinkEnum.CREATE_NODE),
    /**
     * 更新记录节点
     */
    UPDATE_NODE(12, "updateNode", "更新记录节点", "enum.workflowNodeType.memo.update_node", AccessLinkEnum.UPDATE_NODE),
    /**
     * 删除记录节点
     */
    DELETE_NODE(13, "deleteNode", "删除记录节点", "enum.workflowNodeType.memo.delete_node", AccessLinkEnum.DELETE_NODE),
    /**
     * 获取多条数据节点
     */
    MULTI_DATA_NODE(14, "multiDataNode", "获取多条数据节点", "enum.workflowNodeType.memo.multi_data_node", AccessLinkEnum.MULTI_DATA_NODE),

    SINGLE_DATA_NODE(15, "singleDataNode", "获取单条数据节点", "enum.workflowNodeType.memo.single_data_node", AccessLinkEnum.SINGLE_DATA_NODE),
    /**
     * 发送消息节点
     */
    SEND_MESSAGE_NODE(21, "sendMessageNode", "发送消息节点", "enum.workflowNodeType.memo.send_message_node", AccessLinkEnum.SEND_MESSAGE_NODE),

    ;

    /**
     * 节点类型值
     */
    private final Integer type;
    /**
     * 节点类型名称
     */
    private final String name;
    /**
     * 节点类型说明
     */
    private final String description;

    private String memo;

    private AccessLinkEnum accessLinkEnum;

    WorkflowNodeTypeEnum(Integer type, String name, String description,String memo, AccessLinkEnum accessLinkEnum) {
        this.type = type;
        this.name = name;
        this.description = description;
        this.memo = memo;
        this.accessLinkEnum = accessLinkEnum;
    }
    
    public static String getNodeTypeNameByType(Integer type) {
        for (WorkflowNodeTypeEnum anEnum : WorkflowNodeTypeEnum.values()) {
            if (Objects.equals(anEnum.getType(), type)) {
                return anEnum.getName();
            }
        }
        return null;
    }

    public static WorkflowNodeTypeEnum getByType(Integer type) {
        for (WorkflowNodeTypeEnum anEnum : WorkflowNodeTypeEnum.values()) {
            if (Objects.equals(anEnum.getType(), type)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(this.memo);
    }

    /**
     * 可执行的节点
     * @return
     */
    public static List<Integer> getExecutableNodeList() {
        return Arrays.asList(APPROVE_NODE.getType(), CC_NODE.getType(), CREATE_NODE.getType(), UPDATE_NODE.getType(),
                DELETE_NODE.getType(), MULTI_DATA_NODE.getType(), SINGLE_DATA_NODE.getType(), SEND_MESSAGE_NODE.getType());
    }

    public static List<Integer> getDataProcessingNodeList() {
        return Arrays.asList(CREATE_NODE.getType(), UPDATE_NODE.getType(), DELETE_NODE.getType(), MULTI_DATA_NODE.getType(), SINGLE_DATA_NODE.getType());
    }

    public static List<Integer> getApproveNodeList() {
        return Arrays.asList(APPROVE_NODE.getType(), CC_NODE.getType());
    }
}
